from jinja2 import Template, Environment, PackageLoader, FileSystemLoader

import os

from config import BaseConfig


class JsxGenerator:
    def __init__(self, path=BaseConfig.WS_AGENT_JSX_TEMPLATE_PATH):
        self.env = Environment(
            loader=FileSystemLoader(path),
            keep_trailing_newline=True)
        pass

    def get_pages(self, moduleName, pageName, elements, eventFuncs):
        global output
        data = {"module": moduleName, "page": pageName,
                "elements": elements, "eventFuncs": eventFuncs}
        output = self.env.get_template("page.jinja2").render(data)
        output = output.encode('utf-8')


jsx = JsxGenerator()

jsx.get_pages(moduleName="matrix2",
              pageName="test2",
              eventFuncs={"onChange": "aaa", "onSubmit": "e"},
              elements={"MInput": "component/MInput",
                        "Mdata": "component/MData"}
              )

print output
